home *** CD-ROM | disk | FTP | other *** search
- /*
- ** PovRay 2.2 Amiga Display Module for CyberGfx, ECS/AGA Chipset & Workbench 3.0
- **
- ** 1995 by Frank Hoffmann
- */
-
-
- #include "frame.h"
- #include "povproto.h"
-
- #include <proto/exec.h>
- #include <proto/intuition.h>
- #include <proto/graphics.h>
- #include <proto/dos.h>
- #include <proto/expansion.h>
- #include <proto/utility.h>
- #include <exec/types.h>
- #include <intuition/intuition.h>
- #include <graphics/display.h>
- #include <graphics/displayinfo.h>
- #include <graphics/modeid.h>
- #include <graphics/gfxbase.h>
- #include <graphics/gfx.h>
- #include <graphics/videocontrol.h>
- #include <dos/dos.h>
-
- #include <math.h>
- #ifdef _M68881
- #include <m68881.h>
- #endif
-
- //#define MATHERRHANDLER
-
- extern long __oslibversion = 39;
- extern struct GfxBase *GfxBase;
-
- /* Externs from PovRay */
- extern char DisplayFormat;
- extern char PaletteOption;
- extern int Stop_Flag;
-
- /* Function Pointer for Pixel Routine */
- static void (*PixelRoutine)(short x,short y,UBYTE r,UBYTE g,UBYTE b);
-
- /* General Info */
- static struct Screen *screen;
-
- /* ENV */
- static char *PUBSCREENNAME;
-
- /* START Window mode */
- static struct ColorMap *COLORMAP = NULL;
- static struct RastPort *RASTPORT = NULL;
- static struct Window *RWindow = NULL;
-
- static short XOFFSET = 0;
- static short YOFFSET = 0;
-
- static ULONG ColorEntries[256];
-
- static struct Task *WinTask;
- static int WinProc;
- static struct MsgPort *Window_Port;
- /* END Window mode */
-
- /* Optimizations */
- static UBYTE PenLookUpHam8[4][4][4];
-
- static struct colreg { ULONG r,g,b; };
- static struct colreg colback[64];
- static ULONG regsused = 2;
-
- /* Extern ScreenMode Module (modeid.c) */
- extern int GetScreenMode (ULONG *modeID, int *height, int *width , int *autoscroll,int *depth,int,int,ULONG);
-
- /*
- **
- ** Cybergraphics Part
- **
- */
-
- #include <pragmas/cybergraphics_pragmas.h>
- #include <libraries/cybergraphics.h>
-
- /* CyberGfx Prototypes */
-
- ULONG WriteRGBPixel(struct RastPort*,UWORD,UWORD,ULONG);
- BOOL IsCyberModeID(ULONG);
- ULONG GetCyberIDAttr(ULONG,ULONG);
-
- struct Library *CyberGfxBase = NULL;
-
- struct TagItem cybertags[] =
- {
- { CYBRMREQ_WinTitle ,(ULONG)"POVRay 24Bit-Render Screenselection" },
- { CYBRMREQ_MinWidth , 0 } ,
- { CYBRMREQ_MinHeight, 0 } ,
- { CYBRMREQ_MinDepth , 9 } ,
- { TAG_END, TAG_END }
- };
-
-
- struct TagItem cybermodetags[] =
- {
- CYBRBIDTG_NominalWidth ,0,
- CYBRBIDTG_NominalHeight ,0,
- CYBRBIDTG_Depth ,24,
- TAG_END, TAG_END
- };
-
-
- /*
- **
- ** Setup
- **
- */
-
- static void SetPOVTaskPri(LONG pri)
- {
- struct Task* Iam;
-
- if(Iam = FindTask(NULL))
- {
- SetTaskPri(Iam,pri);
- }
- else
- {
- fprintf(stderr,"Error: failed to find myself.\n");
- }
- }
-
- static void DoPOVTaskPri(void)
- {
- char taskpribuf[20];
-
- if(GetVar("POVRAYTASKPRI",taskpribuf,sizeof(taskpribuf),NULL) != 0)
- {
- SetPOVTaskPri(atol(taskpribuf));
- }
- }
-
- /*
- ** control functions
- */
-
- int run_state = 0;
- int ChipSet;
-
- #define CHIPSET_AGA 1
- #define CHIPSET_OLD 0
-
- static int amiga_breakhandle(void)
- {
- if(run_state)
- {
- amiga_close_all();
- return (1);
- }
- else
- {
- return (0);
- }
- }
-
- void amiga_init_POVRAY(void )
- {
- DoPOVTaskPri();
- (void) onbreak(amiga_breakhandle);
- if((GfxBase->ChipRevBits0 & GFXF_AA_ALICE) && (GfxBase->ChipRevBits0 & GFXF_AA_LISA))
- {
- ChipSet = CHIPSET_AGA;
- }
- else
- {
- ChipSet = CHIPSET_OLD;
- }
-
- CyberGfxBase = OpenLibrary("cybergraphics.library",40);
- }
-
- int amiga_close_all (void)
- {
- fprintf(stderr,"\nBreak received!\n");
- Stop_Flag = TRUE;
- close_all();
- return (1);
- }
-
- #ifdef MATHERRHANDLER
- int __matherr (struct __exception *x)
- {
- switch(x->type)
- {
- case DOMAIN:
- case OVERFLOW:
- x->retval = 1.0e17;
- break;
-
- case SING:
- case UNDERFLOW:
- x->retval = 0.0;
- break;
-
- case TLOSS:
- case PLOSS:
- return (0);
- break;
-
- case RANGE:
- #ifdef MATHERRCOUNT
- mathrange++;
- #endif
- return (0);
- break;
-
- default:
- return (0);
- break;
- }
- return(1);
- }
- #endif
-
- /*
- **
- ** Write Pixel Routines
- **
- */
-
- static void write_no_pixel(short x,short y,UBYTE r,UBYTE g,UBYTE b)
- /* dummy function to avoid system crash under certain error conditions */
- { }
-
- static void write_windowsys_pixel(short x,short y,UBYTE r,UBYTE g,UBYTE b)
- /* system friendly color function */
- {
- LONG color;
-
- if((color = ObtainBestPen(COLORMAP,r<<24,g<<24,b<<24,OBP_Precision,PRECISION_IMAGE,TAG_DONE,TAG_DONE))==-1)
- {
- fprintf(stderr,"\nCould not find color!");
- color = 0;
- }
- SetAPen(RASTPORT,(UBYTE)color);
- WritePixel(RASTPORT,XOFFSET+x,YOFFSET+y);
- ColorEntries[color]++;
- }
-
- static void write_windowgrey_pixel(short x, short y,UBYTE r,UBYTE g,UBYTE b)
- /* system friendly gray-color function */
- {
- LONG color;
- ULONG i = (ULONG)(0.3*(double)(b<<24)+0.59*(double)(g<<24)+ 0.11*(double)(b<<24));
-
- if((color = ObtainBestPen(COLORMAP,i,i,i,OBP_Precision,PRECISION_IMAGE,TAG_DONE,TAG_DONE))==-1)
- {
- fprintf(stderr,"\nCould not find color!");
- color = 0;
- }
- SetAPen(RASTPORT,(UBYTE)color);
- WritePixel(RASTPORT,XOFFSET+x,YOFFSET+y);
- ColorEntries[color]++;
- }
-
- static void write_gray8_pixel(short x, short y,UBYTE r,UBYTE g,UBYTE b)
- /* system friendly gray-color function with fixed palette */
- {
- SetAPen(RASTPORT,(UBYTE)(0.3*(double)b+0.59*(double)g+ 0.11*(double)b));
- WritePixel(RASTPORT,XOFFSET+x,YOFFSET+y);
- }
-
- #define absdif(x,y) ((x > y) ? (x - y) : (y - x))
- #define max3(x,y,z) ((x>y)?((x>z)?1:3):((y>z)?2:3))
-
- static short lasty;
- static UBYTE rl,gl,bl;
-
- #define T_MASK 0xC0
- #define MOD_BLUE 64
- #define MOD_RED 128
- #define MOD_GREEN 192
-
- static short last_x = 0,last_y = 0;
- static UBYTE last_red = 0, last_green = 0,last_blue = 0;
-
- __inline static WORD close(UBYTE r,UBYTE g,UBYTE b)
- {
- return (WORD)( ((r&0xc0)>>2) + ((g&0xc0)>>4) + ((b&0xc0)>>6));
- }
-
- __inline static WORD AllocRec(UBYTE r,UBYTE g,UBYTE b)
- {
- return close(r,g,b);
- }
-
- static void write_ham8_pixel(short x,short y,UBYTE r,UBYTE g,UBYTE b)
- {
- UBYTE Red,Green,Blue,delta_red,delta_green,delta_blue;
- UBYTE color;
- BOOL RegUsed = FALSE;
- WORD colorreg;
-
- Red = (r >> 2) & 0x3F;
- Green = (g >> 2) & 0x3F;
- Blue = (b >> 2) & 0x3F;
-
- if(x!=0)
- {
- if(last_x +1 != x || last_y != y)
- return;
- }
-
- if (last_y != y)
- {
- last_y = y;
-
- /* Try to select register !? *) */
-
- if((colorreg = AllocRec(r,g,b)) >= 0)
- {
- last_red = colback[colorreg].r>>24;
- last_green = colback[colorreg].g>>24;
- last_blue = colback[colorreg].b>>24;
- RegUsed = TRUE;
- color = (UBYTE) colorreg;
- }
- else
- {
- last_red = colback[0].r>>24;
- last_green = colback[0].g>>24;
- last_blue = colback[0].b>>24;
- }
- }
-
- last_x = x;
-
- if(!RegUsed)
- {
- delta_red = absdif (r, last_red);
- delta_green = absdif (g, last_green);
- delta_blue = absdif (b, last_blue);
-
- /* if error in more than one channel greater than x,
- try to select register with accuracy y
- if fail, use old method *)
- */
- if((delta_red*delta_red + delta_green*delta_green + delta_blue*delta_blue) > (63*63*3))
- {
- if((colorreg = AllocRec(r,g,b)) >= 0)
- {
- last_red = colback[colorreg].r>>24;
- last_green = colback[colorreg].g>>24;
- last_blue = colback[colorreg].b>>24;
- RegUsed = TRUE;
- color = (UBYTE) colorreg;
- }
- else
- {
- last_red = colback[0].r>>24;
- last_green = colback[0].g>>24;
- last_blue = colback[0].b>>24;
- }
- }
-
- if(!RegUsed)
- {
- switch (max3(delta_red, delta_green, delta_blue))
- {
- case 1:
- last_red = r;
- color = MOD_RED + Red;
- break;
- case 2:
- last_green = g;
- color = MOD_GREEN + Green;
- break;
- case 3:
- last_blue = b;
- color = MOD_BLUE + Blue;
- break;
- }
- }
- }
-
- SetAPen(RASTPORT, color);
- WritePixel(RASTPORT, XOFFSET+x, YOFFSET+y);
- }
-
- static void write_ham6_pixel(short x,short y,UBYTE r,UBYTE g,UBYTE b)
- /*
- ** Routine from Povray 2.2 orginal Sourcecode
- */
- {
- UBYTE Red,Green,Blue,delta_red,delta_green,delta_blue;
- UBYTE color;
-
- Red = (r >> 4) & 0x0F;
- Green = (g >> 4) & 0x0F;
- Blue = (b >> 4) & 0x0F;
-
- if(x!=0)
- {
- if(last_x +1 != x || last_y != y)
- return;
- }
-
- if (last_y != y)
- {
- last_y = y;
- last_red = last_green = last_blue = 0;
- }
-
- last_x = x;
-
- delta_red = absdif (Red, last_red);
- delta_green = absdif (Green, last_green);
- delta_blue = absdif (Blue, last_blue);
-
- switch (max3(delta_red, delta_green, delta_blue))
- {
- case 1:
- last_red = Red;
- color = 0x20 + Red;
- break;
- case 2:
- last_green = Green;
- color = 0x30 + Green;
- break;
- case 3:
- last_blue = Blue;
- color = 0x10 + Blue;
- break;
- }
-
- SetAPen(RASTPORT, color);
- WritePixel(RASTPORT, XOFFSET+x, YOFFSET+y);
- }
-
- static void write_Cyber24_pixel(short x, short y,UBYTE r,UBYTE g,UBYTE b)
- /* CyberGfx direct Color pixel routine */
- {
- ULONG color = (((ULONG)r)<<16) + (((ULONG)g)<<8) + ((ULONG)b);
- /* Note: Alpha Channel remains zero */
-
- WriteRGBPixel(RASTPORT,XOFFSET+x,YOFFSET+y,color);
- }
-
- /*
- **
- ** Init and Clean Routines
- **
- */
-
- static void DoCube4(struct Screen* screen)
- /* Generate 4*4*4 = 64 Palette for HAM 8 Picture */
- {
- ULONG r,g,b;
- UBYTE c=0;
-
- struct cmap
- {
- ULONG col;
- ULONG c[64][3];
- ULONG pad;
- }cmap;
-
- cmap.col = (64l<<16)+0;
- cmap.pad = 0;
-
- for(r=0;r<4;r++)
- {
- for(g=0;g<4;g++)
- {
- for(b=0;b<4;b++)
- {
- cmap.c[r*4*4+g*4+b][0] = (0xffffffff/3)*r;
- cmap.c[r*4*4+g*4+b][1] = (0xffffffff/3)*g;
- cmap.c[r*4*4+g*4+b][2] = (0xffffffff/3)*b;
- PenLookUpHam8[r][g][b] = c;
- c++;
- }
- }
- }
-
- LoadRGB32(&screen->ViewPort,(ULONG*)&cmap);
- }
-
- void display_finished (void)
- {
- if(RWindow)
- {
- fprintf(stderr,"\nFinished.\nClose window to quit\n");
- }
- }
-
- void display_init (int input_width,int input_height)
- {
- ULONG i;
- char namebuffer[256];
-
- PixelRoutine = write_no_pixel;
- PUBSCREENNAME = NULL;
- screen = NULL;
- RWindow = NULL;
-
- run_state = 1; // enable CTRL-C
-
- memset(ColorEntries,0,256);
-
- if(DisplayFormat == 'W')
- {
- ULONG modeid;
-
- /* if POVWINDOWSCREEN is defined, copy it to PUBSCEENNAME */
- if(GetVar("POVWINDOWSCREEN",namebuffer,256,NULL)!=-1)
- {
- PUBSCREENNAME = namebuffer;
- }
-
- if(!(screen = LockPubScreen(PUBSCREENNAME)))
- {
- fprintf(stderr,"\nCould not lock public screen!\n");
- return;
- }
-
- XOFFSET = screen->WBorLeft;
- YOFFSET = screen->WBorTop+screen->Font->ta_YSize+1;
-
- if(((XOFFSET+screen->WBorRight+input_width) > screen->Width)
- ||((YOFFSET+screen->WBorBottom+input_height) > screen->Height))
- {
- fprintf(stderr,"\nCould not open window of inner size: with %d height %d.\n",input_width,input_height);
- UnlockPubScreen(NULL,screen);
- return;
- }
-
- if(!(RWindow = OpenWindowTags(NULL,
- WA_PubScreen, screen,
- WA_Left, screen->MouseX,
- WA_Top, screen->MouseY,
- WA_InnerWidth, input_width,
- WA_InnerHeight, input_height,
- WA_IDCMP, IDCMP_ACTIVEWINDOW|IDCMP_INACTIVEWINDOW|
- IDCMP_CLOSEWINDOW,
- WA_DragBar, TRUE,
- WA_DepthGadget, TRUE,
- WA_RMBTrap, TRUE,
- WA_CloseGadget, TRUE,
- WA_ScreenTitle, "POV Ray Rendering...",
- WA_Title, "POV Ray Window",
- WA_GimmeZeroZero, TRUE,
- TAG_END,TAG_END)))
- {
- fprintf(stderr,"\nCould not open Window\n");
- UnlockPubScreen(NULL,screen);
- return;
- }
-
- XOFFSET=0;
- YOFFSET=0;
-
- /* set needed structs */
- RASTPORT = RWindow->RPort;
- COLORMAP = screen->ViewPort.ColorMap;
-
- modeid = GetVPModeID(&screen->ViewPort);
-
- UnlockPubScreen(NULL,screen);
-
- if(PaletteOption == 'G')
- {
- PixelRoutine = write_windowgrey_pixel;
- }
- else if(PaletteOption == 'S')
- {
- PixelRoutine = write_windowsys_pixel;
- }
- else
- {
- PixelRoutine = write_windowsys_pixel;
-
- if(CyberGfxBase)
- {
- if(IsCyberModeID(modeid))
- {
- if(GetCyberIDAttr(CYBRIDATTR_PIXFMT,modeid) != PIXFMT_LUT8)
- {
- PixelRoutine = write_Cyber24_pixel;
- }
- }
- }
- }
-
- return;
- }
- else if( (DisplayFormat == 'P') || (DisplayFormat == 'S'))
- {
- ULONG modeid, inID;
- struct DimensionInfo dinfo;
- char *dummy;
- int as,sheight,swidth,depth = 8;
-
- modeid = BestModeID(BIDTAG_NominalWidth ,input_width,
- BIDTAG_NominalHeight ,input_height,
- BIDTAG_Depth , 8,
- BIDTAG_RedBits ,(UBYTE)8,
- TAG_END);
- inID = modeid;
-
- if(modeid == INVALID_ID)
- {
- /* DO ECS STUFF ? */
- fprintf(stderr,"\nNo matching modeid found!\n");
- return;
- }
-
- if(PaletteOption == '1')
- {
- if(GetVar("POVSCREENMODEID",namebuffer,256,NULL)!=-1)
- {
-
- inID = strtol(namebuffer,&dummy,16);
- if(inID != 0) modeid = inID;
- if(ModeNotAvailable(modeid) != NULL)
- {
- return;
- }
- }
- }
-
- if(PaletteOption == '2')
- {
- modeid = BestModeID(
- BIDTAG_NominalWidth ,input_width,
- BIDTAG_NominalHeight ,input_height,
- BIDTAG_DesiredWidth ,input_width,
- BIDTAG_DesiredHeight ,input_height,
- BIDTAG_Depth , 8,
- BIDTAG_RedBits ,(UBYTE)8,
- TAG_END);
- }
-
- if(!GetDisplayInfoData(NULL,(UBYTE*)&dinfo,sizeof(struct DimensionInfo),DTAG_DIMS,modeid))
- {
- fprintf(stderr,"Could not get dimensions information form screenmode!\n");
- exit(0);
- }
-
- if(PaletteOption == '0')
- {
- depth = 1;
- if(GetScreenMode(&inID,&sheight,&swidth,&as,&depth,input_width,input_height,DIPF_IS_WB))
- {
- modeid = inID;
- }
- else
- {
- depth = 8;
- swidth = dinfo.Nominal.MaxX;
- sheight = dinfo.Nominal.MaxY;
- }
- }
- else if(PaletteOption == 'G')
- {
- depth = -8;
- if(GetScreenMode(&inID,&sheight,&swidth,&as,&depth,input_width,input_height,DIPF_IS_WB))
- {
- modeid = inID;
- }
- else
- {
- depth = 8;
- swidth = dinfo.Nominal.MaxX;
- sheight = dinfo.Nominal.MaxY;
- }
- }
- else
- {
- swidth = dinfo.Nominal.MaxX;
- sheight = dinfo.Nominal.MaxY;
- }
-
-
- XOFFSET = (swidth - input_width)/2;
- YOFFSET = (sheight - input_height)/2;
-
- if(DisplayFormat == 'P')
- {
-
- if(!(screen = OpenScreenTags(NULL,
- SA_Width, swidth,
- SA_Height, sheight,
- SA_Depth, depth,
- SA_Type, PUBLICSCREEN,
- SA_PubName, PUBSCREENNAME,
- SA_DisplayID, modeid,
- SA_Behind, TRUE,
- SA_SharePens, TRUE,
- SA_Title, "POVRay Rendering Screen",
- TAG_END)))
- {
- fprintf(stderr,"\nCould not open screen!\n");
- return;
- }
-
- if(!(RWindow = OpenWindowTags(NULL,
- WA_PubScreen, screen,
- WA_Left, XOFFSET,
- WA_Top, YOFFSET,
- WA_InnerWidth, input_width,
- WA_InnerHeight, input_height,
- WA_IDCMP, IDCMP_CLOSEWINDOW|IDCMP_RAWKEY,
- WA_DragBar, TRUE,
- WA_DepthGadget, TRUE,
- WA_RMBTrap, TRUE,
- WA_CloseGadget, TRUE,
- WA_GimmeZeroZero, TRUE,
- TAG_END,TAG_END)))
- {
- fprintf(stderr,"\nCould not open Window\n");
- CloseScreen(screen);
- return;
- }
- XOFFSET = 0;
- YOFFSET = 0;
- RASTPORT = RWindow->RPort;
- }
- else
- {
- if(!(screen = OpenScreenTags(NULL,
- SA_Width, swidth,
- SA_Height, sheight,
- SA_Depth, depth,
- SA_Type, CUSTOMSCREEN,
- SA_PubName, PUBSCREENNAME,
- SA_DisplayID, modeid,
- SA_SharePens, TRUE,
- SA_Behind, TRUE,
- SA_Quiet, TRUE,
- SA_Title, "POVRay Rendering Screen",
- TAG_END)))
- {
- fprintf(stderr,"\nCould not open screen!\n");
- return;
- }
-
- /* to get intuition messages for now */
- if(!(RWindow = OpenWindowTags(NULL,
- WA_CustomScreen, screen,
- WA_Left, 0,
- WA_Top, 0,
- WA_InnerWidth, swidth,
- WA_InnerHeight, sheight,
- WA_IDCMP, IDCMP_CLOSEWINDOW|IDCMP_RAWKEY,
- WA_DragBar, FALSE,
- WA_DepthGadget, FALSE,
- WA_RMBTrap, TRUE,
- WA_CloseGadget, FALSE,
- WA_GimmeZeroZero, TRUE,
- WA_Borderless, TRUE,
- WA_Backdrop, TRUE,
- TAG_END,TAG_END)))
- {
- fprintf(stderr,"\nCould not open Window\n");
- CloseScreen(screen);
- return;
- }
- RASTPORT = &screen->RastPort;
- }
-
- COLORMAP = screen->ViewPort.ColorMap;
-
- if(PaletteOption == 'G')
- {
- for(i=0;i<256;i++)
- {
- SetRGB32(&screen->ViewPort,i,i<<24,i<<24,i<<24);
- }
- PixelRoutine = write_gray8_pixel;
- }
- else if(PaletteOption == 'F')
- {
- PixelRoutine = write_windowgrey_pixel;
- }
- else
- {
-
- PixelRoutine = write_windowsys_pixel;
-
- if(CyberGfxBase)
- {
- if(IsCyberModeID(modeid))
- {
- if(GetCyberIDAttr(CYBRIDATTR_PIXFMT,modeid) != PIXFMT_LUT8)
- {
- PixelRoutine = write_Cyber24_pixel;
- }
- }
- }
- }
-
- if(screen) ScreenToFront(screen);
- }
- else if(DisplayFormat == 'H')
- {
- ULONG modeid, inID;
- struct DimensionInfo dinfo;
- char *dummy;
- int sheight,swidth,depth = 8,as;
-
- lasty = -1;
- rl = 0; gl = 0; bl = 0;
-
- modeid = BestModeID(BIDTAG_NominalWidth ,input_width,
- BIDTAG_NominalHeight ,input_height,
- BIDTAG_Depth , 8,
- BIDTAG_RedBits ,(UBYTE)8,
- BIDTAG_DIPFMustHave , DIPF_IS_HAM,
- TAG_END);
- inID = modeid;
-
- if(modeid == INVALID_ID)
- {
- /* DO ECS STUFF ? */
- fprintf(stderr,"\nNo matching modeid found!\n");
- return;
- }
-
- if(PaletteOption == '2' || PaletteOption == '3')
- {
- if(GetVar("POVRAYHAMMODEID",namebuffer,256,NULL)!=-1)
- {
-
- inID = strtol(namebuffer,&dummy,16);
- if(inID != 0) modeid = inID;
- if(ModeNotAvailable(modeid) != NULL)
- {
- return;
- }
- }
- }
-
- if(PaletteOption == '1')
- {
-
- if(ChipSet = CHIPSET_AGA) depth = 8; else depth = 6;
-
- modeid = BestModeID(
- BIDTAG_NominalWidth ,input_width,
- BIDTAG_NominalHeight ,input_height,
- BIDTAG_DesiredWidth ,input_width,
- BIDTAG_DesiredHeight ,input_height,
- BIDTAG_Depth ,depth,
- BIDTAG_DIPFMustHave ,DIPF_IS_HAM,
- TAG_END);
- }
-
- if(GetDisplayInfoData(NULL,(UBYTE*)&dinfo,sizeof(struct DimensionInfo),DTAG_DIMS,modeid))
- {
-
- }
-
- if(PaletteOption == '0')
- {
- depth = 6;
- if(GetScreenMode(&inID,&sheight,&swidth,&as,&depth,input_width,input_height,DIPF_IS_HAM))
- {
- modeid = inID;
- }
- else
- {
- depth = 8;
- swidth = dinfo.Nominal.MaxX;
- sheight = dinfo.Nominal.MaxY;
- }
- }
- else
- {
- swidth = dinfo.Nominal.MaxX;
- sheight = dinfo.Nominal.MaxY;
- }
-
- XOFFSET = (swidth - input_width)/2;
- YOFFSET = (sheight - input_height)/2;
-
- if(PaletteOption == '2')
- {
- if(ChipSet == CHIPSET_AGA)
- {
- depth = 8;
- }
- else
- {
- depth = 6;
- }
- }
-
- if(PaletteOption == '3')
- {
- depth = 6;
- }
-
- if(!(screen = OpenScreenTags(NULL,
- SA_Top, 0,
- SA_Left, 0,
- SA_Width, swidth,
- SA_Height, sheight,
- SA_Depth, depth,
- SA_Type, CUSTOMSCREEN,
- SA_DisplayID, modeid,
- SA_Quiet, TRUE,
- SA_AutoScroll, TRUE,
- SA_Draggable, TRUE,
- SA_Behind, TRUE,
- SA_Interleaved, TRUE,
- SA_Title, NULL,
- TAG_END)))
- {
- fprintf(stderr,"\nCould not open screen!\n");
- return;
- }
-
- /* to get intuition messages */
- if(!(RWindow = OpenWindowTags(NULL,
- WA_CustomScreen, screen,
- WA_Left, 0,
- WA_Top, 0,
- WA_InnerWidth, swidth,
- WA_InnerHeight, sheight,
- WA_IDCMP, IDCMP_CLOSEWINDOW|IDCMP_RAWKEY,
- WA_DragBar, FALSE,
- WA_DepthGadget, FALSE,
- WA_RMBTrap, TRUE,
- WA_CloseGadget, FALSE,
- WA_GimmeZeroZero, TRUE,
- WA_Borderless, TRUE,
- WA_Backdrop, TRUE,
- WA_Activate, TRUE,
- TAG_END,TAG_END)))
- {
- fprintf(stderr,"\nCould not open Window\n");
- CloseScreen(screen);
- return;
- }
-
- RASTPORT = &screen->RastPort;
- COLORMAP = screen->ViewPort.ColorMap;
-
- DoCube4(screen);
-
- last_y = -1;
- last_x = -1;
-
- if(((PaletteOption == '2') || (PaletteOption == '0')) && (depth == 8) && (ChipSet == CHIPSET_AGA))
- {
- GetRGB32(screen->ViewPort.ColorMap,0,64,(ULONG*)colback);
-
- PixelRoutine = write_ham8_pixel; // write_ham8_pixel;
- }
- else
- {
- PixelRoutine = write_ham6_pixel;
- }
-
- if(screen) ScreenToFront(screen);
- }
- }
-
- void display_close (void)
- {
- if(RWindow)
- {
- ULONG i,j;
- ULONG colors = 0;
- struct IntuiMessage* IMes;
- ULONG class;
- BOOL running = TRUE;
-
- if(Stop_Flag != TRUE)
- {
- ULONG Signal;
-
- DisplayBeep(NULL);
-
- run_state = 0;
- do
- {
- // WaitPort(RWindow->UserPort);
- Signal = Wait(SIGBREAKF_CTRL_C | (1<< RWindow->UserPort->mp_SigBit));
-
- if(Signal & (1<< RWindow->UserPort->mp_SigBit))
- {
- IMes = (struct IntuiMessage*) GetMsg(RWindow->UserPort);
-
- class = IMes->Class;
- ReplyMsg((struct Message*)IMes);
-
- if(class == IDCMP_CLOSEWINDOW) running = FALSE;
- if(class == IDCMP_RAWKEY) running = FALSE;
- }
- else if (Signal & SIGBREAKF_CTRL_C)
- {
- running = FALSE;
- }
-
- }while(running);
- }
-
- CloseWindow(RWindow);
-
- for(i=0;i<256;i++)
- {
- if(ColorEntries[i] > 0)
- {
- colors++;
-
- for(j=0;j<ColorEntries[i];j++)
- {
- ReleasePen(COLORMAP,i);
- }
- }
- }
- if(colors) fprintf(stderr,"\n%lu colors used!\n",colors);
- }
-
- if(screen)
- {
- if(DisplayFormat == 'W') UnlockPubScreen(NULL,screen);
- else CloseScreen(screen);
- }
-
- if(CyberGfxBase) { CloseLibrary(CyberGfxBase); CyberGfxBase = NULL; }
- }
-
- void display_plot (int x,int y,UBYTE Red,UBYTE Green,UBYTE Blue)
- {
- PixelRoutine((short)x,(short)y,Red,Green,Blue);
- }
-